package string;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class OccurrencesAfterBigram1078 {
    public String[] findOcurrences(String text, String first, String second) {
        String[] strings = text.split(" ");
        String[] result = new String[]{};
        if(strings.length<2){
            return result;
        }
        String s1 = strings[0];
        String s2 = strings[1];
        List<String> list = new ArrayList<>();
        for (int i = 2; i < strings.length; i++) {
            if(s1.equals(first)&&s2.equals(second)){
                list.add(strings[i]);
            }
            s1 = s2;
            s2 = strings[i];
        }
        return list.toArray(result);
    }
}
